package com.cloud.pole.weixin.wechat.http;

public class HttpConstant {
    /**
     * 创建菜单
     */
    private final static String CREATE_MENU_URL = "https://api.weixin.qq" +
            ".com/cgi-bin/menu/create?access_token";

    /**
     * 获取access_token
     */
    private final static String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq" +
            ".com/cgi-bin/token?grant_type=client_credential&appid";

    /**
     * 查询菜单
     */
    private final static String GET_MENU_URL = "https://api.weixin.qq" +
            ".com/cgi-bin/menu/get?access_token";

    /**
     * 取消菜单
     */
    private final static String DELETE_MENU_URL = "https://api.weixin.qq" +
            ".com/cgi-bin/menu/delete?access_token";

    /**
     * 关注者列表
     */
    private final static String SUBSCRIBE_USER_URL = "https://api.weixin.qq" +
            ".com/cgi-bin/user/get?access_token";

    /**
     * 获取用户基本信息
     */
    private final static String SUBSCRIBE_USER_INFO_URL = "https://api.weixin.qq" +
            ".com/cgi-bin/user/info?lang=zh_CN&access_token";

    /**
     * 发送客服消息
     */
    private final static String CUSTOMER_SEND_URL = "https://api.weixin.qq" +
            ".com/cgi-bin/message/custom/send?access_token";

    private final static String GET_SNSAPI_BASE = "https://api.weixin.qq" +
            ".com/sns/oauth2/access_token?";

    /**
     * 获得创建菜单URL
     *
     * @param access_token access_token
     * @return 创建菜单URL
     */
    public static String getCreateMenuURL(String access_token) {
        return access_token != null && !"".equals(access_token) ? CREATE_MENU_URL
                + "=" + access_token
                : "";
    }

    /**
     * 获得access_token URL
     *
     * @param appid appid
     * @param secret secret
     * @return access_token URL
     */
    public static String getAccessTokenURL(String appid, String secret) {
        return secret != null && !"".equals(secret) && appid != null
                && !"".equals(appid) ? GET_ACCESS_TOKEN_URL + "=" + appid
                + "&secret=" + secret : "";
    }

    /**
     * 查询菜单URL
     *
     * @param access_token access_token
     * @return 查询菜单URL
     * 
     */
    public static String getMenuURL(String access_token) {
        return access_token != null && !"".equals(access_token) ? GET_MENU_URL
                + "=" + access_token : "";
    }

    /**
     * 取消菜单URL
     *
     * @param access_token access_token
     * @return 取消菜单URL
     * 
     */
    public static String getDeleteMenuURL(String access_token) {
        return access_token != null && !"".equals(access_token) ? DELETE_MENU_URL
                + "=" + access_token
                : "";
    }

    /**
     * 关注者用户列表
     *
     * @param access_token 调用接口凭证
     * @param next_openid  第一个拉取的OPENID，不填默认从头开始拉取
     * @return 关注者用户列表
     * 
     */
    public static String getSubscribeUserURL(String access_token,
                                             String next_openid) {
        return access_token != null && !"".equals(access_token)
                && next_openid != null ? SUBSCRIBE_USER_URL + "="
                + access_token + "&next_openid=" + next_openid : "";
    }

    /**
     * 获取关注者用户的基本信息
     *
     * @param access_token 调用接口凭证
     * @param openId       关注者微信ID
     * @return 关注者用户的基本信息
     */
    public static String getSubscribeUserInfoURL(String access_token,
                                                 String openId) {
        return access_token != null && !"".equals(access_token)
                && openId != null ? SUBSCRIBE_USER_INFO_URL + "="
                + access_token + "&openid=" + openId : "";
    }

    /**
     * 获取发送客服消息接口地址
     *
     * @param access_token access_token
     * @return 发送客服消息接口地址
     */
    public static String getSendCustomerURL(String access_token) {
        return access_token != null && !"".equals(access_token) ? CUSTOMER_SEND_URL + "=" + 
                access_token : "";
    }

    /**
     * 网页授权获取openid
     *
     * @param appId appId
     * @param appSecret appSecret
     * @param code code
     * @return 网页授权URL
     */
    public static String getSnsapiBaseURl(String appId, String appSecret, String code) {
        return code != null && !"".equals(code) ? GET_SNSAPI_BASE + "appid=" + appId + "&secret="
                +appSecret + "&code=" + code +
                "&grant_type=authorization_code" : "";
    }
}
